package cn.forge.mall.framework.security.config;

import cn.forge.mall.framework.security.core.filter.SecurityContextClearingFilter;
import cn.forge.mall.framework.security.core.filter.TokenAuthenticationFilter;
import cn.forge.mall.framework.security.core.handler.AuthenticationEntryPointImpl;
import cn.forge.mall.framework.web.core.GlobalExceptionHandler;
import cn.forge.mall.system.api.oauth2.OAuth2TokenApi;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.security.web.AuthenticationEntryPoint;

/**
 * @author liangyuanping
 * @ClassName ForgeSecurityAutoConfiguration
 * @description:
 * @date 2024年03月20日
 * @version: 1.0
 */
@AutoConfiguration
public class ForgeSecurityAutoConfiguration {

    @Bean
    public SecurityContextClearingFilter securityContextClearingFilter(){
        return new SecurityContextClearingFilter();
    }
    @Bean
    public TokenAuthenticationFilter tokenAuthenticationFilter(OAuth2TokenApi oAuth2TokenApi, GlobalExceptionHandler globalExceptionHandler){
        return new TokenAuthenticationFilter(oAuth2TokenApi,globalExceptionHandler);
    }

    /**
     * 认证失败处理类 Bean
     */
    @Bean
    public AuthenticationEntryPoint authenticationEntryPoint() {
        return new AuthenticationEntryPointImpl();
    }
}
